extends Node



var animation_item := preload("res://entity/animation/animation_item.tscn")


#添加节点
func add_scene(scene, pos: Vector2 = Vector2.ZERO, scale: Vector2 = Vector2.ZERO, rotation: float = 0.0, parent: Node = null) -> void:
	var obj: Node2D = scene if scene is Node2D else scene.instantiate()
	if pos.length(): obj.global_position = pos
	if scale.length(): obj.scale = scale
	if rotation != 0.0: obj.rotation = rotation
	
	var parent_node : Node = parent if parent != null else get_tree().root
	parent_node.add_child.call_deferred(obj)


#单个动画
func add_animation(animation_name: String, pos: Vector2 = Vector2.ZERO, scale: Vector2 = Vector2.ZERO, rotation: float = 0.0, speed_scale: float = 1.0, mdlt: Color = Color.WHITE, parent: Node = null) -> void:
	var animation : Node2D = Global.animation_item.instantiate()
	if pos.length(): animation.global_position = pos
	if scale.length(): animation.scale = scale
	if rotation != 0.0: animation.rotation = rotation
	if mdlt != Color.WHITE: animation.modulate = mdlt
	animation.get_node("AnimatedSprite2D").speed_scale = speed_scale
	animation.get_node("AnimatedSprite2D").animation = animation_name
	
	var parent_node : Node = parent if parent != null else get_tree().root
	parent_node.add_child.call_deferred(animation)
	animation.call_deferred("play", animation_name)
